package com.wwlwxg.netty;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.string.StringEncoder;

import java.net.InetSocketAddress;

public class CloseFutureClient {

	public static void main(String[] args) throws InterruptedException {
		NioEventLoopGroup group = new NioEventLoopGroup();
		ChannelFuture future = new Bootstrap().group(group)
				.channel(NioSocketChannel.class)
				.handler(new ChannelInitializer<NioSocketChannel>() {
					@Override
					protected void initChannel(NioSocketChannel ch) throws Exception {
						ch.pipeline().addLast(new StringEncoder());
					}

				}).connect(new InetSocketAddress("localhost", 8888));
//		future.addListener(new ChannelFutureListener() {
//			@Override
//			public void operationComplete(ChannelFuture channelFuture) throws Exception {
//				channelFuture.channel().writeAndFlush("aaa");
//			}
//		});

		future.sync().channel().writeAndFlush("aaaaaa");

	}
}
